package com.hdf.etdemo.view.listview.adapter;

import java.util.List;
import java.util.Map;

import com.hdf.etdemo.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 */
public class GridViewAdapter extends BaseAdapter {

	private Context context;
	private List<Map<String, Object>> list;
	private LayoutInflater inflater;

	public GridViewAdapter(Context context, List<Map<String, Object>> list) {
		this.context = context;
		this.list = list;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		HolderView holderView;
		if (convertView == null) {
			holderView = new HolderView();
			convertView = inflater.inflate(R.layout.item_photo, null);
			holderView.php_title = (TextView) convertView.findViewById(R.id.php_title);
			holderView.php_img = (ImageView) convertView.findViewById(R.id.php_img);

			convertView.setTag(holderView);
		} else {
			holderView = (HolderView) convertView.getTag();
		}
		ImageLoader.getInstance().displayImage(list.get(position).get("imgurl").toString(), holderView.php_img);
		holderView.php_title.setText(list.get(position).get("name").toString());
		return convertView;
	}

	private class HolderView {
		private TextView php_title;
		private ImageView php_img;

	}

}
